package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("api/v1/sensitive")
public class WmSensitiveController {

    @Autowired
    private WmSensitiveService wmSensitiveService;

    /**
     * 获取敏感词列表
     * @param sensitiveDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody SensitiveDto sensitiveDto){
        return wmSensitiveService.getList(sensitiveDto);
    }

    /**
     * 删除敏感词
     * @param id
     * @return
     */
    @DeleteMapping("del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        wmSensitiveService.removeById(id);
        return ResponseResult.okResult("");
    }

    /**
     * 新增
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.save(wmSensitive);
        return ResponseResult.okResult("");
    }

    /**
     * 修改
     * @param wmSensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        wmSensitiveService.updateById(wmSensitive);
        return ResponseResult.okResult("");
    }
}
